home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / Shareware City / Developers / Mac F2C 1.0 / For '(Project Models)' / Mac F2C Project / main.c < prev   
Encoding:
C/C++ Source or Header  |  1994-05-16  |  2.1 KB  |  134 lines  |  [TEXT/KAHL]

  1. /* STARTUP PROCEDURE FOR UNIX FORTRAN PROGRAMS */
  2.  
  3. #include "stdio.h"
  4. #include "signal.h"
  5.  
  6. #ifndef SIGIOT
  7. #define SIGIOT SIGABRT
  8. #endif
  9.  
  10. #ifdef THINK_C
  11. #include <console.h>    /* IMT 11 Apr 94 Needed to make command line work on Macintosh */
  12. #endif
  13.  
  14. #ifndef KR_headers
  15. #include "stdlib.h"
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20.  
  21. #ifdef NO__STDC
  22. #define ONEXIT onexit
  23. extern void f_exit();
  24. #else
  25. #ifndef KR_headers
  26. extern void f_exit(void);
  27. #ifndef NO_ONEXIT
  28. #define ONEXIT atexit
  29. extern int atexit(void (*)(void));
  30. #endif
  31. #else
  32. #ifndef NO_ONEXIT
  33. #define ONEXIT onexit
  34. extern void f_exit();
  35. #endif
  36. #endif
  37. #endif
  38.  
  39. #ifdef KR_headers
  40. extern void f_init(), sig_die();
  41. extern int MAIN__();
  42. #define Int /* int */
  43. #else
  44. extern void f_init(void), sig_die(char*, int);
  45. extern int MAIN__(void);
  46. #define Int int
  47. #endif
  48.  
  49. static void sigfdie(Int n)
  50. {
  51. sig_die("Floating Exception", 1);
  52. }
  53.  
  54.  
  55. static void sigidie(Int n)
  56. {
  57. sig_die("IOT Trap", 1);
  58. }
  59.  
  60. #ifdef SIGQUIT
  61. static void sigqdie(Int n)
  62. {
  63. sig_die("Quit signal", 1);
  64. }
  65. #endif
  66.  
  67.  
  68. static void sigindie(Int n)
  69. {
  70. sig_die("Interrupt", 0);
  71. }
  72.  
  73. static void sigtdie(Int n)
  74. {
  75. sig_die("Killed", 0);
  76. }
  77.  
  78. #ifdef SIGTRAP
  79. static void sigtrdie(Int n)
  80. {
  81. sig_die("Trace trap", 1);
  82. }
  83. #endif
  84.  
  85.  
  86. int xargc;
  87. char **xargv;
  88.  
  89. #ifdef KR_headers
  90. main(argc, argv) int argc; char **argv;
  91. #else
  92. main(int argc, char **argv)
  93. #endif
  94. {
  95.  
  96. #ifdef THINK_C
  97.     argc = ccommand( &argv );        /* IMT 11 Apr 94 Macintosh mod (no command line) */
  98. #endif
  99.  
  100. xargc = argc;
  101. xargv = argv;
  102. signal(SIGFPE, sigfdie);    /* ignore underflow, enable overflow */
  103. signal(SIGIOT, sigidie);
  104. #ifdef SIGTRAP
  105. signal(SIGTRAP, sigtrdie);
  106. #endif
  107. #ifdef SIGQUIT
  108. if(signal(SIGQUIT,sigqdie) == SIG_IGN)
  109.     signal(SIGQUIT, SIG_IGN);
  110. #endif
  111. if(signal(SIGINT, sigindie) == SIG_IGN)
  112.     signal(SIGINT, SIG_IGN);
  113. signal(SIGTERM,sigtdie);
  114.  
  115. #ifdef pdp11
  116.     ldfps(01200); /* detect overflow as an exception */
  117. #endif
  118.  
  119. f_init();
  120. #ifndef NO_ONEXIT
  121. ONEXIT(f_exit);
  122. #endif
  123. MAIN__();
  124. #ifdef NO_ONEXIT
  125. f_exit();
  126. #endif
  127. exit(0);    /* exit(0) rather than return(0) to bypass Cray bug */
  128. return 0;    /* For compilers that complain of missing return values; */
  129.         /* others will complain that this is unreachable code. */
  130. }
  131. #ifdef __cplusplus
  132.     }
  133. #endif
  134.